import router from './router'
import {
	getToken
} from '@/utils/auth'

const whiteList = ['/login'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
	const { path } = to
	document.title = to.meta.title
	const hasToken = getToken()
	
	if (hasToken) {
		next()
	} else {
		if (whiteList.indexOf(path) !== -1) {
			next()
		} else {
			next(`/login?redirect=${path}`)
		}
	}
})
